//
//  ReplyViewController.m
//  beike
//
//  Created by jiangshao on 15-3-29.
//  Copyright (c) 2015年 com.buildcoo. All rights reserved.
//

#import "ReplyViewController.h"
#import "SVProgressHUD.h"
//#import "MobClick.h"

@interface ReplyViewController (){
    BOOL isEmpty;
}

@end

@implementation ReplyViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title=@"意见反馈";
    
    contact.font=Font(16);
    [contact setPadding:YES top:0 right:0 bottom:0 left:10];
    content.font=Font(16);
    contact.delegate=self;
    self.feedback = [UMFeedback sharedInstance];
    self.feedback.delegate = self;
    placeholder.text = @"有什么意见快告诉我们吧！";
    placeholder.textColor=[UIColor lightGrayColor];
    placeholder.font=Font(16);
    content.delegate=self;
    

    UIBarButtonItem *postdata= [[UIBarButtonItem alloc]initWithTitle:@"提交" style:UIBarButtonItemStylePlain target:self action:
                                @selector(postdata:)];
    self.navigationItem.rightBarButtonItem=postdata;
    
    UIFont* font = Font(16);
    NSDictionary* textAttributes = @{NSFontAttributeName:font,
                                     NSForegroundColorAttributeName:RGBCOLOR(171, 63, 20)};
    [[UIBarButtonItem appearanceWhenContainedIn:[UINavigationBar class], nil] setTitleTextAttributes:textAttributes forState:UIControlStateNormal];
    
    // Do any additional setup after loading the view.
}


- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
    if (textField == contact) {
        //        [nameTextfiled resignFirstResponder];
        [textField resignFirstResponder];
        [self postdata:nil];
        return  YES;
    }
    [textField resignFirstResponder];
    return YES;
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(IBAction)postdata:(id)sender{
    if ([content.text isEqualToString:@""]) {
        [SVProgressHUD showErrorWithStatus:@"意见不能为空"];
        return;
    }
    NSMutableDictionary *postContent =[[NSMutableDictionary alloc]init];
    NSString *usertext=[NSString stringWithFormat:@"%@ \r\n ",content.text];
    [postContent setObject:usertext forKey:@"content"];
    [postContent setObject:@"user_reply" forKey:@"type"];
    
    if (![contact.text isEqualToString:@""]){
       [[UMFeedback sharedInstance] updateUserInfo:@{@"contact": @{@"phone": contact.text}}];
    }
    [[UMFeedback sharedInstance] post:postContent];
    [self.navigationController popViewControllerAnimated:YES];
    [SVProgressHUD showSuccessWithStatus:@"提交成功"];

}

-(void)viewDidAppear:(BOOL)animated{
    [content becomeFirstResponder];
}

//-(void)viewWillAppear:(BOOL)animated{
//    [MobClick beginLogPageView:self.title];
//    [AppGlobal hiddenTabbar:self];
//}



//-(void)viewWillDisappear:(BOOL)animated{
//    [MobClick endLogPageView:self.title];
//}




- (void)textViewDidChange:(UITextView *)textView{
    if(content.text.length == 0){
        placeholder.hidden = NO;
    }else{
        placeholder.hidden = YES;
    }

}


//- (void)postFinishedWithError:(NSError *)error {
//    if (error != nil) {
//        NSLog(@"%@", error);
//    } else {
//        NSLog(@"%@", self.feedback.topicAndReplies);
//    }
//}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
